package cn.itsource.controller;

import cn.itsource.domain.User;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class OrderController {

    @Autowired
    private RestTemplate restTemplate;

    @HystrixCommand(fallbackMethod = "fallback")
    @RequestMapping("/getuser/{id}")
    public User getUser(@PathVariable("id") Long id){
        User user = restTemplate.getForObject("http://SERVICE-USER/getuser/" + id, User.class);
        return user;
    }

    public User fallback(@PathVariable("id") Long id){

        return new User(-1L,"sb", "sbl");
    }

}
